﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using DataAccess.Datatypes;
using DataModel;
using System.Web.Helpers;
using BussinesLayer.Services;

namespace Mvc4.Controllers
{
    public class HomeController : Controller
    {
        private SiteServices ss = new SiteServices();

        [Authorize]
        public ActionResult Chat()
        {
            //var context = new SignalRChat.Models.UsersContext();
            //var lista = from m in context.UserProfiles select m;
            return View();
        }

        public ActionResult Index()
        {
            ViewBag.SiteName = "OL4RENT";
            IEnumerable<Site> sites = ss.GetNSites(10); //Devuelve 10 sitios elegidos al azar
            return View(sites);
        }

        public void GetImage(int siteId)
        {
            byte[] logo = ss.GetSiteLogo(siteId);
            WebImage webImage;
            if (logo == null)
            {
                webImage = new WebImage("~/images/no_image.jpg");
                webImage.FileName = "no_image.jpg";
            }
            else
            {
                webImage = new WebImage(logo);
                webImage.FileName = "site.jpeg";
            }
            webImage.Resize(150, 150);
            webImage.Write();
        }

        public ActionResult Error()
        {
            return HttpNotFound();
        }
    }
}
